TestCase
(
	'org.puremvc.js.core.ControllerTest'
,	{
		testGetInstance: function ()
		{
			var controller= Controller.getInstance()
			
			assertTrue('The controller instance was retrieved correctly', controller && controller instanceof Controller);
		}
		
	,	testRegisterAndExecuteCommand: function ()
		{
			var controller= Controller.getInstance();
			controller.registerCommand('ControllerTest', ControllerTestCommand)
			
			var vo= new ControllerTestVo(12);
			var note= new Notification('ControllerTest', vo);
			
			controller.executeCommand(note);
			
			assertSame('The command was executed successfully by Controller', 24, vo.result);
		}
		
	,	testRegisterAndRemoveCommand: function ()
		{
   			// Create the controller, register the ControllerTestCommand to handle 'ControllerTest' notes
   			var controller = Controller.getInstance();
   			controller.registerCommand('ControllerRemoveTest', ControllerTestCommand);
   			
   			// Create a 'ControllerTest' note
   			var vo = new ControllerTestVo( 12 );
   			var note = new Notification( 'ControllerRemoveTest', vo );

			// Tell the controller to execute the Command associated with the note
			// the ControllerTestCommand invoked will multiply the vo.input value
			// by 2 and set the result on vo.result
   			controller.executeCommand(note);
   			
   			// test assertions 
   			assertTrue( "Expecting vo.result == 24", vo.result == 24 );
   			
   			// Reset result
   			vo.result = 0;
   			
   			// Remove the Command from the Controller
   			controller.removeCommand('ControllerRemoveTest');
			
			// Tell the controller to execute the Command associated with the
			// note. This time, it should not be registered, and our vo result
			// will not change   			
   			controller.executeCommand(note);
   			
   			// test assertions 
   			assertTrue( "Expecting vo.result == 0", vo.result == 0 );
		}
		
	,	testHasCommand: function ()
		{
			var controller= Controller.getInstance()
			controller.registerCommand('hasCommandTest', ControllerTestCommand);
			
			assertTrue('The Controller has the command', controller.hasCommand('hasCommandTest'));
			
			controller.removeCommand('hasCommandTest');
			
			assertFalse('The Controller does not have the command', controller.hasCommand('hasCommandTest'));
		}
		
	,	testReRegisterAndExecuteCommand: function ()
		{
			   			// Fetch the controller, register the ControllerTestCommand2 to handle 'ControllerTest2' notes
   			var controller = Controller.getInstance();
   			controller.registerCommand('ControllerTest2', ControllerTestCommand2);
   			
   			// Remove the Command from the Controller
   			controller.removeCommand('ControllerTest2');
			
   			// Re-register the Command with the Controller
   			controller.registerCommand('ControllerTest2', ControllerTestCommand2);

   			// Create a 'ControllerTest2' note
   			var vo = new ControllerTestVo( 12 );
   			var note = new Notification( 'ControllerTest2', vo );

			// retrieve a reference to the View.
   			var view = View.getInstance();
   			
			// send the Notification
   			view.notifyObservers(note);
   			
   			// test assertions 
			// if the command is executed once the value will be 24
			assertTrue( "Expecting vo.result == 24", vo.result == 24 );

   			// Prove that accumulation works in the VO by sending the notification again
   			view.notifyObservers(note);
   			
			// if the command is executed twice the value will be 48
			assertTrue( "Expecting vo.result == 48", vo.result == 48 );
		}
	}
);
